Repository navigation
Migrate GenerateStaticWebAssetEndpointsManifest to IMultiThreadableTask - #54706
Conversation
Follow-up: deeper call-stack audit (call paths into StaticWebAsset)Tracing all helpers invoked from
Both Why it doesn't bite in practice today: in production the SDK targets that produce these items populate Why not fix it here: |
70e2f63 to
78804f7
Compare
There was a problem hiding this comment.
Pull request overview
Migrates GenerateStaticWebAssetEndpointsManifest to MSBuild’s multi-threadable task model (IMultiThreadableTask + [MSBuildMultiThreadableTask]) so multithreaded builds can avoid the per-task TaskHost wrapper and correctly root relative paths against TaskEnvironment.ProjectDirectory.
Changes:
- Implement
IMultiThreadableTaskonGenerateStaticWebAssetEndpointsManifestand introduceTaskEnvironmentwithTaskEnvironment.Fallback. - Absolutize
ManifestPath/CacheFilePath/ExclusionPatternsCacheFilePathonce viaTaskEnvironment.GetAbsolutePathand route file I/O through those absolute paths. - Add a regression test ensuring relative manifest + exclusion-cache writes are rooted to
TaskEnvironment.ProjectDirectory(not the process CWD).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsManifest.cs |
Makes the task multi-threadable and redirects file operations to TaskEnvironment-rooted absolute paths. |
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestMultiThreadingTest.cs |
Adds coverage asserting the task’s outputs do not depend on the process current directory. |
78804f7 to
3a56cb8
Compare
Marks the task with [MSBuildMultiThreadableTask] and implements IMultiThreadableTask. ManifestPath, CacheFilePath, and ExclusionPatternsCacheFilePath are absolutized once at the top of Execute via TaskEnvironment.GetAbsolutePath and threaded into the helper UpdateExclusionPatternsCache (now static). Log messages still emit the original ManifestPath. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirrors the StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest pattern: set process CWD to a decoy directory in a different subtree, run the task with TaskEnvironment bound to a separate project directory, and assert the endpoints manifest + exclusion-patterns cache files are written under TaskEnvironment.ProjectDirectory (not the decoy CWD). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match the defensive pattern used elsewhere in StaticWebAsset (e.g., NormalizeContentRootPath, ResolveFile) — skip absolutization when the input is null or empty instead of letting GetAbsolutePath throw. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3a56cb8 to
a591136
Compare
…d, inline bool variables - Revert UpdateExclusionPatternsCache from static back to instance method, using ExclusionPatternsCacheFilePath property directly for the guard check - Remove hasCacheFile and hasExclusionCache bool variables, inline the checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ifestPath The conditional expression's best common type resolves to 'string' when one branch is the 'string'-typed ManifestPath, because AbsolutePath defines an implicit conversion to string but not from string. Assigning that string result back to the AbsolutePath variable fails with CS0029. Use ': default' (matching the cacheAbsolutePath/exclusionCacheAbsolutePath lines), which resolves the conditional type to AbsolutePath. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Treat null/empty/whitespace path inputs uniformly by switching the
GetAbsolutePath guards from IsNullOrEmpty to IsNullOrWhiteSpace, so a
whitespace-only ManifestPath/CacheFilePath/ExclusionPatternsCacheFilePath
never reaches TaskEnvironment.GetAbsolutePath (which throws) nor
File.WriteAllText("") in the exclusion cache path.
Addresses review feedback on dotnet#54706.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Treat null/empty/whitespace path inputs uniformly by switching the
GetAbsolutePath guards from IsNullOrEmpty to IsNullOrWhiteSpace, so a
whitespace-only ManifestPath/CacheFilePath/ExclusionPatternsCacheFilePath
never reaches TaskEnvironment.GetAbsolutePath (which throws) nor
File.WriteAllText("") in the exclusion cache path.
Addresses review feedback on dotnet#54706.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f7d855bc-b3c6-4511-b408-f544667cc54e
Preserve whitespace-only Unix paths and keep manifest diagnostics using the original relative path while file I/O uses the task environment's absolute path. Update the regression tests for MSTest after rebasing onto main. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f7d855bc-b3c6-4511-b408-f544667cc54e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f7d855bc-b3c6-4511-b408-f544667cc54e
acc3440 to
c133a29
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
| public override bool Execute() | ||
| { | ||
| var absoluteManifestPath = !string.IsNullOrEmpty(ManifestPath) ? TaskEnvironment.GetAbsolutePath(ManifestPath) : (AbsolutePath?)null; | ||
| var manifestAbsolutePath = absoluteManifestPath?.Value ?? ManifestPath; |
There was a problem hiding this comment.
I think we do not need this variable, we can use absoluteManifestPath only but make a default value ManifestPath, not null
There was a problem hiding this comment.
And I would rename it to "manifestAbsolutePath" to keep naming consistent
There was a problem hiding this comment.
Done in 4f103fd — went with your version.
There's now a single manifestAbsolutePath string, consistent with the two cache paths, and it falls back to ManifestPath instead of null. The branch around PersistFileIfChanged is gone too.
Two knock-on changes:
- The
AbsolutePathoverload I had added toArtifactWriteris unused now, so I reverted that file — the PR is back to one product file. - The low-importance
Creating artifact because artifact file '...'message now prints the absolute path. That matches how the rest of the file operations in this task behave, and the task's ownGenerating manifest file '{0}'messages still use the relativeManifestPath. I updated the MT test assertion accordingly.
No functional change — all GenerateStaticWebAssetEndpointsManifest tests pass locally.
| }; | ||
|
|
||
| this.PersistFileIfChanged(manifest, ManifestPath, StaticWebAssetsJsonSerializerContext.RelaxedEscaping.StaticWebAssetEndpointsManifest); | ||
| if (absoluteManifestPath is { } path) |
There was a problem hiding this comment.
We not need this additional check, if this comment https://github.com/dotnet/sdk/pull/54706/changes#r3645107700 will be resolved
There was a problem hiding this comment.
Done in 4f103fd — the branch is gone, there's a single PersistFileIfChanged call now.
Collapse absoluteManifestPath/manifestAbsolutePath into a single string variable, consistent with the cache paths, and drop the branch around PersistFileIfChanged. The ArtifactWriter AbsolutePath overload is no longer used, so revert that file to its original state; the low-importance "Creating artifact" message now logs the absolute path, matching how the other file operations in this task are logged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@OvesN applied both suggestions in 4f103fd — single |
The multithreading test nested <ClassName>/<guid>/decoy/spawn under the test binary directory, which pushed Directory.SetCurrentDirectory past MAX_PATH and threw PathTooLongException on developer machines with a moderately long repo path (Helix's short C:\h\w paths hid this in CI). Shorten the scratch layout and add the same parallelization comment the sibling StaticWebAssets multithreading tests carry. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Refreshed this PR and chased down the red CI (build 1534425). Why it was red: two unrelated Helix work items failed — What actually needed fixing: the new multithreading test nested Also merged current |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
Migrates
GenerateStaticWebAssetEndpointsManifest(src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsManifest.cs) toIMultiThreadableTaskso MSBuild''s multithreaded mode bypasses the per-task TaskHost wrapper.Fixes dotnet/msbuild#14034
Perfstar regression (14d, Windows, paired MT vs non-MT, p50 sum across iterations)
GenerateStaticWebAssetsManifestChanges
[MSBuildMultiThreadableTask]+ implementsIMultiThreadableTaskwith defaultTaskEnvironment.Fallback.ManifestPath,CacheFilePath, andExclusionPatternsCacheFilePathare absolutized once at the top ofExecuteviaTaskEnvironment.GetAbsolutePath, guarded bystring.IsNullOrEmptyso a null/empty value is passed through unchanged. AllFile.*calls use the absolutized values; the task''s own log messages still emit the originalManifestPath.Compatibility sins audit (per migration skill)
[Output]property on this task.Log.LogMessage("Updating manifest timestamp ''{0}''", ManifestPath)calls still use the original property. The low-importanceArtifactWriterdiagnostic now prints the absolute path.??swallowing exceptions): no new null-coalescing.GetAbsolutePath("")throwsArgumentException.ManifestPathis[Required]; optionalCacheFilePathandExclusionPatternsCacheFilePathare guarded bystring.IsNullOrEmptybefore callingGetAbsolutePath.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com